﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Liu_Project.Utils
{
    public class Function
    {
        /// <summary>
        /// MD5 加密
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string GetMD5(string strData)
        {
            if (string.IsNullOrWhiteSpace(strData))
            {
                return string.Empty;
            }
            //实例化一个md5对象
            System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] data = System.Text.Encoding.Default.GetBytes(strData);//将字符编码为一个字节序列
            byte[] md5data = md5.ComputeHash(data);//计算 data 字节数组的哈希值
            md5.Clear();
            var sb = new StringBuilder();
            for (int i = 0; i < md5data.Length; i++)
            {
                sb.Append(md5data[i].ToString("x").PadLeft(2, '0'));
            }
            return sb.ToString();
        }
    }
}
